<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<title>青年旅行家</title>
		<link rel="stylesheet" type="text/css" href="../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../css/base.css" />
	</head>
	<body>
		<div class="login-wrap" id='header'>
			<a class="close" href="#" tapmode="" onclick="api.closeWin()"></a>
			<h2 class="login-h"><a class="login-reg" href="#" tapmode="" onclick="openLogin();;api.closeWin();">登录</a></h2>
			<ul class="login-form reg-form">
				<li class="bt">
					<span>手机号</span>
					<input class="login-form-input" type="text" value="" name="" id='phone' />
				</li>
				<li class="bt">
					<span>验证码</span>
					<input class="login-form-input reg-input-code" type="text" value="" name="" />
					<a class="reg-get-code" href="#" onclick="SendSms()" tapmode="" id='btnSend'>获取短信验证码</a>
					<span class="reg-get-code td-no  hidden" id="leftTime">倒计时60秒</span>
				</li>
				<li class="bt">
					<span>密码</span>
					<input class="login-form-input" type="password" value="" name="" id='pwd1' />
				</li>
				<li>
					<span>确认密码</span>
					<input class="login-form-input" type="password" value="" name="" id='pwd2' />
				</li>
			</ul>
			<a class="initial-reg-btn" href="#" tapmode="" onclick="ensure()">立即注册</a>
			<p class="login-agree-p">
				点击登录即表示同意<a class="login-agree-con" href="#">用户协议</a>
			</p>
		</div>
	</body>
	<script type="text/javascript" src="../script/api.js"></script>
	<script type="text/javascript" src="../script/app.js"></script>
	<script type="text/javascript" src="../script/zepto.min.js"></script>
	<script type="text/javascript" src="../script/yzxVerification.js"></script>
	<script type="text/javascript">
		var SECONDS = 60;
		var leftSecs = SECONDS;
		//剩余时间
		var isSend = true;
		//能够发送短信
		var code = '1234';
		var notOk = true;
		//没有确认
		var notOverTime = true;
		//没有超时
		var notSend = true;
		//没有发送短信码
		var t;
		function SetText() {
			if (leftSecs > 0) {
				var str = "倒计时" + leftSecs + "秒";
				$('#leftTime').text(str);
				t = setTimeout('SetText()', 1000);
			} else {
				isSend = true;
				notOverTime = true;
				leftSecs = SECONDS;
				$('#leftTime').addClass('hidden');
				$('#btnSend').removeClass('hidden');
				//alert("短信超时，请从新发送短信认证码！");
			}
			leftSecs -= 1;
		}

		function SendSms() {
			if (isSend) {
				isSend = false;
				notSend = false;
				var str = "倒计时" + leftSecs + "秒";
				leftSecs -= 1;
				$('#leftTime').removeClass('hidden');
				$('#leftTime').text(str);
				$('#btnSend').addClass('hidden');
				notOverTime = false;
				t = setTimeout('SetText()', 1000);
			}
		}

		function ensure() {
			//openRegister2();
			isSend = true;
			$('#leftTime').text('');
			if (notSend) {
				alert("没有发送短信码，请发送短信认证码！");
				notOverTime = false;
			} else if (notOverTime) {
				alert("短信超时,请从新发送短信认证码！");
				notOverTime = false;
			} else {
				t && clearTimeout(t);
				leftSecs = SECONDS;
				notOk = true;
				isSend = true;
				$('#leftTime').addClass('hidden');
				$('#btnSend').removeClass('hidden');
				//api.openWinalert("正在提交");
				if ($("#phone").val() == "") {
					alert("please input phone");
					return;
				}
				var phone = $("#phone").val();
				var pwd1 = $("#pwd1").val();
				var pwd2 = $("#pwd2").val();
				if (pwd1 != pwd2) {
					alert('2次密码不相等，请从新输入确认密码！');
					$("#pwd2").text('');
				} else {
					var data = {};
					//data.userId='83';
					data.userName = phone;
					data.userSN = '';
					data.phone = phone;
					data.email = '';
					data.password = md5(pwd1);
					data.signature = '';
					//testUpfile1();
					var url = '/rest/user/register';
					ajaxRequest(url, 'post', data, function(ret, err) {
						//var ret=JSON.parse(ret);
						//alert(ret.body);
						if (ret.body) {
							//log(ret);
							var uid = ret.body.userId;
							$api.setStorage('uid', uid);
							$api.setStorage('pwd', data.password);
							api.closeWin();
							openRegister2();
						} else if (ret.error) {
							alert('用户已注册，请直接登录！');
						} else {
							alert('注册失败，请从新注册！');
						}
						//else
						//	alert(JSON.stringify(err));
					});
				}
			}
		}

		apiready = function() {
			var $header = $api.byId('header');
			$api.fixIos7Bar($header);
		}
	</script>
</html>